<template>
  <div id="applyHistory">
    <el-tabs v-model="activeName"
             class="tabPlane"
             @tab-click="handleClick">
      <el-tab-pane label="提交历史"
                   name="first">
        <div class="contentClass">
          <el-table :data="historyList"
                    style="width: 100%">
            <el-tableColumn type="index"
                            label="序号"
                            width="100">
            </el-tableColumn>
            <el-table-column prop="commitTime"
                             label="提交时间">
            </el-table-column>
            <el-table-column prop="auditor"
                             label="审核人">
            </el-table-column>
            <el-table-column prop="auditTime"
                             label="审核时间">
            </el-table-column>
            <el-table-column prop=""
                             label="审核状态">
              <template slot-scope="scope">
                <span v-if="scope.row.auditStatus === 0">待审核</span>
                <span v-if="scope.row.auditStatus === 1">通过</span>
                <span v-if="scope.row.auditStatus === -1">驳回</span>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <b style="color: #0af; cursor: pointer;"
                   @click="showDetail(scope.$index, historyList)">查看详情</b>
                <b style="color: #0af; cursor: pointer;"
                   @click="changeAgain(scope.$index, historyList)"
                   v-if="scope.row.commitTime === maxtime && scope.row.auditStatus === -1">再次修改</b>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import { student } from '@api/index'
export default {
  name: 'applyHistory',
  data () {
    return {
      activeName: 'first',
      historyList: [],
      maxtime: ''
    }
  },
  mounted () {
    this.initPage()
  },
  methods: {
    // 初始化函数
    initPage () {
      this.getHistoryList()
    },
    getHistoryList () {
      // 获取提交历史列表
      student()._getCommitHistoryList().then((res) => {
        this.historyList = []
        if (res.status) {
          this.historyList.push(...res.data)
          let historyLists = this.historyList.filter((item, index, arr) => item.auditStatus)
          let timeslist = []
          historyLists.forEach(function (item1) {
            timeslist.push(new Date(item1.commitTime).getTime())
          })
          timeslist.sort()
          this.maxtime = this.$moment(timeslist[timeslist.length - 1]).format('YYYY-MM-DD HH:mm:ss')
        }
      })
    },
    showDetail (index, data) {
      this.$router.push({
        name: 'student_applyStatus',
        query: {
          auditId: data[index].auditId
        }
      })
    },
    changeAgain (index, data) {
      this.$router.push({
        name: 'student_updateOwnInfo',
        query: {
          auditId: data[index].auditId,
          type: 2
        }
      })
    },
    handleClick (tab, event) {
      console.log(tab, event)
    }
  }
}
</script>
